import { Component } from '@angular/core';
import {HttpClient, HttpClientModule} from "@angular/common/http";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  sg: string;
  tz: string;
  result: number;
  suggest: string;
  imgurl:string;
  suggestvalue:string;
  constructor(private http: HttpClient) {
  }


  getBmiValue() {
    console.log("身高是" + this.sg + "体重是" + this.tz);
    let parm = {
      "sg": this.sg,
      "tz": this.tz
    }
    let url = "http://localhost:8080/bmivalue";
    this.http.post(url,parm).toPromise()
      .then((data:any)=>{
        console.dir(data);
        this.result=data.result;
        this.suggest=data.suggest;
        switch (this.suggest){
          case "fat":
            this.imgurl="/assets/img/bigfat.jpg";
            this.suggestvalue="你太胖了，要少吃点";
            break;
          case "normal":
            this.imgurl="/assets/img/normal.jpg";
            this.suggestvalue="你的形体十分正常";
            break;
          case "overwight":
            this.imgurl="/assets/img/timg.jpg";
            this.suggestvalue="你有点婴儿肥哦，少吃点";
            break;
          case "thin":
            this.suggestvalue="你太瘦了，多吃点";
            this.imgurl="/assets/img/thin.jpg";

            break;

        }
      });


  }



}
